package com.healthcare;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import webservices.HealthCareServerProxy;

/**
 * Servlet implementation class DocComment
 */
public class DocComment extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DocComment() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		String userid = request.getParameter("data");
		String docid =	request.getSession().getAttribute("docid").toString();
			System.out.println("docid inside Article"+docid);
			//System.out.println("hi");
			int usId = Integer.parseInt(userid);
			int dcid = Integer.parseInt(docid);
			//Boolean postStatus = false;
			String status = "false";
					//User user = new User(inputfname, inputLastName, inputEmail, inputAge,
						//	inputGender, inputPassword);
					HealthCareServerProxy proxy = new HealthCareServerProxy();
					if(proxy.deleteUsers(usId,dcid));
					{
						status="done";
						request.setAttribute("status", status);
					RequestDispatcher dispatcher = request.getRequestDispatcher("/DocUsersList.jsp");
					System.out.println("inside the delet");
					
					
					
					dispatcher.forward(request, response);
					System.out.println("inside the delet11");
					}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
	

System.out.println("inside comment");
//if((request.getParameter("cmt")!= null))
//{
String user=request.getSession().getAttribute("user").toString();
	String data = request.getParameter("data").trim();
	System.out.println("inside comment1");
	String id = data.substring(0, 1);
	String comment = data.substring(3).trim();
	
	//String row = "name:12345";
	String[] columns = data.split("\\$");
	assert columns.length == 2;
	String comment1 = columns[0].trim();
	String id1= columns[1];
	
	 DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
		Date date = new Date();
	System.out.println("comment" +comment1);
	System.out.println("id" +id1);
	System.out.println("user" +user);

	HealthCareServerProxy proxy = new HealthCareServerProxy();
	proxy.savedocComment(id1, comment1, user, dateFormat.format(date));
	RequestDispatcher dispatcher = request.getRequestDispatcher("/DocListPosts.jsp");
		
	dispatcher.forward(request, response);


		
	}

}
